//导入自定义类
import java.time.*;
import java.util.*;
import com.zhoulei.employee.*;

import java.util.Random;
import java.lang.ClassNotFoundException.*; //Class.forName
public class Main {
    public static void main(String[] args) {
        System.out.println("this is main()");
        //实例化员工
        Employee[] employees;
        employees = new Employee[]{
                new Employee("xm", 1, LocalDate.of(2017, 10, 12), 10000),
                new Employee("xh", 1, LocalDate.of(2018, 10, 12), 20000),
                new Employee("xl", 1, LocalDate.of(2019, 10, 12), 30000),
                new Employee("xy", 1, LocalDate.of(2020, 10, 12), 40000)
        };

        //加薪
        for (Employee e : employees) {
            System.out.println(e.getName() + ":" + e.getId() + " 原薪资：" + e.getSalary() + "现薪资：" + e.raiseSalary(20));
        }

        Manager manager = new Manager("yy", 32, LocalDate.of(2019, 4, 3), 10000, 2000);
        System.out.println(manager.getName() + ":" + manager.getId() + " 原薪资：" + manager.getSalary() + "现薪资：" + manager.raiseSalary(20));

        if (employees[0] instanceof Employee)
            System.out.println("Employee!");
        else System.out.println("Manager");

        //person
        Person[] p = new Person[]{
                new Student("zl", "math"),
                new Employee("zl", 23, LocalDate.of(2019, 10, 23), 2300),
                new Manager("zl", 23, LocalDate.of(2019, 10, 23), 2300, 3400)
        };
        for (Person p1 : p)
            System.out.println(p1.getDes());

        //ArrayList
        ArrayList<Person> arr = new ArrayList<Person>();
        arr.add(new Student("zl", "math"));
        arr.add(new Employee("zl", 23, LocalDate.of(2019, 10, 23), 2300));
        arr.add(new Manager("zl", 23, LocalDate.of(2019, 10, 23), 2300, 3400));
        arr.set(0, new Student("zl", "chinese"));
        for (Person it : arr) {
            System.out.println(it.getDes());
        }
        for (int i = 0; i < arr.size(); i++) {
            System.out.println(arr.get(i).getDes());
        }

        //测试可变参数变量
        double[] dd = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 4};
        System.out.println(Arrays.toString(dd));
        System.out.println(getMax(dd));
        System.out.println(getMax(1, 2, 3, 4, 5, 6, 7, 8, 4));

        //反射

        Employee em = new Employee("zk", 2, LocalDate.of(2019, 2, 4), 32);
        Class c1 = em.getClass();
        System.out.println(c1.getName() + " " + em.getName());
        if (em.getClass() == Employee.class)
            System.out.println("类型相同");
        //-由字符串获得类型
        String strRandom = "java.util.Random";
        try {
            Class cc = Class.forName(strRandom);
        } catch (Exception e) {
            e.printStackTrace(); //打印栈轨迹
        }

        //-由反射创建一个对象
        try{
            Object o = Class.forName(strRandom).newInstance();
            if(o.getClass() == Random.class)
            {
                System.out.println("o is random");
            }
        }catch(Exception e)
        {
            e.printStackTrace(); //打印栈轨迹
        }
       //-利用反射分析类的能力

    }

    //可变参数
    public static double getMax(double ... values){
        double maxD = Double.NEGATIVE_INFINITY;
        for(double b : values)
            if(b > maxD) maxD = b;
        return maxD;
    }
}
